<%@ page language="java" pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<style type="text/css">
	#companyMap td {background: #FFF;}
</style>
<input id="txtPlace" type="text" style="width:50%;" />
<input type="button" value="搜索" onclick="search()" style="width:60px;margin-left:10px;" />
<label style="color:#F00;font-weight:bold;margin-left:10px;">请点击地图获得经纬度</label>
<div id="companyMap" style="width:830px;height:300px;margin-top:6px;background:none;"></div>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=ZpeqqjBYGfj18IBgLDBwN6iY"></script>
<script type="text/javascript">
	// 百度地图API功能
	var map = new BMap.Map("companyMap");
  	map.setDefaultCursor("crosshair");//设置地图默认的鼠标指针样式
  	var point = null;
  	<c:choose>
		<c:when test="${!empty param.lng && !empty param.lat}">
			point = new BMap.Point(${param.lng}, ${param.lat});
		</c:when>
		<c:otherwise>
			point = new BMap.Point(113.32736,23.140608);
		</c:otherwise>
	</c:choose>
  	/* if(${param.lng} != null && ${param.lat} != null) {
  		point = new BMap.Point(${param.lng}, ${param.lat});
  	} else {
  		point = new BMap.Point(${param.lng}, ${param.lat});
  	} */
	map.centerAndZoom(point, 19); //地图级别19
	map.enableScrollWheelZoom(); //地图允许可伸缩
 	map.addEventListener("click", function(e){//地图单击事件
 		$("#txtLng").val(e.point.lng);
 		$("#txtLat").val(e.point.lat);
 	}); 
  	//添加定位红点
  	var marker = new BMap.Marker(point);
	//marker.setAnimation(BMAP_ANIMATION_BOUNCE); //跳动的动画
	map.addOverlay(marker);
	  
	var opts = {
	  width : 300,     // 信息窗口宽度
	  height: 100,     // 信息窗口高度
	  title : "${param.companyName}" , // 信息窗口标题
	  enableMessage:true //设置允许信息窗发送短息
	  //message:"亲耐滴，晚上一起吃个饭吧？戳下面的链接看下地址喔~"
	}
	var infoWindow = new BMap.InfoWindow("地址：${param.address}", opts);  // 创建信息窗口对象 
	map.openInfoWindow(infoWindow,point); //开启信息窗口
	marker.addEventListener("click", function(){          
		map.openInfoWindow(infoWindow,point); //开启信息窗口
	});
	
	//根据目标位置进行搜索
  	function search() {
		var local = new BMap.LocalSearch(map, {
			renderOptions:{map: map}
		});
		var content = $("#txtPlace").val();
		local.search(content, 17);
  	}
</script>